package com.wlyuan.open.infrastructure.jobhandler;

import com.wlyuan.open.application.service.PushService;
import com.wlyuan.open.infrastructure.config.PushProperties;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author
 * 推送服务
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class PushJobHandler extends IJobHandler{

    private final PushProperties pushProperties;
    private final PushService pushService;


    private Long getBulkBatchSize() {
        return pushProperties.getJobSize();
    }

    public void handle() {
        Long size = this.getBulkBatchSize();
        pushService.push(1L,size);
    }

    @Override
    @XxlJob("PushJob")
    public void execute() {
        XxlJobHelper.log("创建推送数据任务...");
        this.handle();
        XxlJobHelper.log("创建推送数据任务完成...");
        XxlJobHelper.handleSuccess();
    }

}
